﻿using Compass.Wasm.Shared;
using Compass.Wasm.Shared.Plans;
using System.Net.Http.Json;

namespace Compass.Wasm.Client.Services.Plans;
public interface IIssueService : IBaseService<IssueDto>
{
    //扩展查询
    Task<List<IssueDto>> GetAllByMainPlanIdAsync(Guid mainPlanId);
    Task<HttpResponseMessage> UpdateSolutionAsync(Guid id, IssueDto dto);
}
public class IssueService : BaseService<IssueDto>, IIssueService
{
    private readonly HttpClient _http;
    private const string ServiceName = "Issue";
    public IssueService(HttpClient http) : base(http, ServiceName)
    {
        _http = http;
    }

    public async Task<List<IssueDto>> GetAllByMainPlanIdAsync(Guid mainPlanId)
    {
        var response=await  _http.GetFromJsonAsync<ApiResponse<List<IssueDto>>>($"api/{ServiceName}/MainPlan/{mainPlanId}");
        return response.Status ? response.Result : new List<IssueDto>();
    }
    public Task<HttpResponseMessage> UpdateSolutionAsync(Guid id, IssueDto dto)
    {
        return _http.PutAsJsonAsync($"api/{ServiceName}/UpdateSolution/{id}", dto);
    }
}